package cn.rdq.iknessplatform.controller;

import cn.rdq.api.dto.BlogShowDto;
import cn.rdq.api.po.Drama;
import cn.rdq.api.vo.BlogVo;
import cn.rdq.api.vo.DramaVo;
import cn.rdq.common.CommonResult;
import cn.rdq.iknessplatform.service.BlogService;
import cn.rdq.iknessplatform.service.DramaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private BlogService blogService;

    @Autowired
    private DramaService dramaService;

    @GetMapping
    public CommonResult query(@NotBlank(message = "关键字不能为空") String keyword) {
        BlogVo blogVo = new BlogVo();
        blogVo.setTitle(keyword);
        blogVo.setCurrentPage(1);
        blogVo.setPageSize(999);

        DramaVo dramaVo = new DramaVo();
        dramaVo.setTitle(keyword);
        dramaVo.setCurrentPage(1);
        dramaVo.setPageSize(999);

        List<BlogShowDto> blogs = blogService.listBlogBrief(blogVo);
        List<Drama> dramas = dramaService.query(dramaVo);

        Map<String, Object> map = new HashMap<>(16);
        map.put("blogs", blogs);
        map.put("dramas", dramas);
        return CommonResult.successObj(map);
    }

}
